home *** CD-ROM | disk | FTP | other *** search
/ Informática Multimedia 1995 April / Informatica Multimedia CD - Epimundo.iso / DOS / FILEFIND / FFF / PROCARC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-12  |  3.2 KB  |  116 lines

  1. /***************************************************************************
  2.  *                                                                         *
  3.  * ARC Processing Functions                                                *
  4.  * These routines are used to process files with an ARC extension.         *
  5.  * Since PAK produces files with the same format as is used by ARC, the    *
  6.  * same routines are used to process files with the PAK extension also     *
  7.  **************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11.  
  12. #include "fff.h"
  13. #include "arc.h"
  14.  
  15. int Match (char *Str, char *Pat);
  16. void PrtVerbose (char *Path, char *Name, DOS_FILE_TIME *Time, DOS_FILE_DATE *Date,
  17.                  long Size);
  18. void ChkPage (void);
  19. static int GetEntry (FILE *ArcFile, ARCHIVE_HEADER *ArchiveDir);
  20. int  SearchQ (char *Str);
  21.  
  22. /***********************************************************************
  23.  * DoArc is the main routine for processing ARC and PAK files.         *
  24.  **********************************************************************/
  25.  
  26.  void
  27. DoArc (char *Path) {
  28.     extern int Level;
  29.     extern int TotalMatch, VerboseSwt, CaseSwt, Spaced, PageSwt;
  30.     extern char V_Name[14], V_Path[66];
  31.     extern ARC_TYPE ArcType;
  32.     extern int Lnno;
  33.     extern S[6][3];
  34.  
  35.     FILE *ArcFile;
  36.     int Status, Printed;
  37.     ARCHIVE_HEADER ArchiveHead;
  38.  
  39.     Printed = 0;
  40.     if ( (ArcFile = fopen(Path, "rb")) == NULL) perror(Path);
  41.     else {
  42.         while ( (Status = GetEntry(ArcFile, &ArchiveHead)) != 0 ) {
  43.             if (Status < 0) {
  44.                 printf("%s\n", Path);
  45.                 break;
  46.                 }
  47.             else {
  48.                 ++S[ArcType][1];
  49.                 if ( SearchQ(ArchiveHead.Name) ) {
  50.                     ++S[ArcType][2];
  51.                     ++TotalMatch;
  52.                     if (PageSwt) ChkPage();
  53.                     strcpy(V_Name, ArchiveHead.Name);
  54.                     strcpy(V_Path, Path);
  55.                     if (CaseSwt == ON) {
  56.                         strlwr(V_Name);
  57.                         strlwr(V_Path);
  58.                         }
  59.                     if (VerboseSwt) {
  60.                         if (!Printed) {
  61.                             if (!Spaced) {
  62.                                 if (PageSwt) ChkPage();
  63.                                 printf("\n");
  64.                                 ++Lnno;
  65.                                 }
  66.                             if (PageSwt) ChkPage();
  67.                             printf("%s\n", V_Path);
  68.                             ++Lnno;
  69.                             Printed = 1;
  70.                             }
  71.                         fputs("* ", stdout);
  72.                         PrtVerbose("", V_Name, &ArchiveHead.Time,
  73.                                    &ArchiveHead.Date, ArchiveHead.Length);
  74.                         }
  75.                     else {
  76.                         fputs(V_Path, stdout);
  77.                         fputs("--> (", stdout);
  78.                         fputs(V_Name, stdout);
  79.                         puts(")");
  80.                         }
  81.                     ++Lnno;
  82.                     }
  83.                 }
  84.             }
  85.         fclose(ArcFile);
  86.         }
  87.     if (Printed) {
  88.         if (PageSwt) ChkPage();
  89.         printf("\n");
  90.         ++Lnno;
  91.         Spaced = 1;
  92.         }
  93.     }
  94.  
  95. /***********************************************************************
  96.  * GetEntry will read and verify the next entry in the distributed     *
  97.  * directory of an ARC or PAK file.                                    *
  98.  ***********************************************************************/
  99.  
  100.  static int
  101. GetEntry (FILE *ArcFile, ARCHIVE_HEADER *ArchiveDir) {
  102.  
  103.     if (fread(ArchiveDir, sizeof(char), sizeof(ARCHIVE_HEADER), ArcFile) < 2) {
  104.         printf("couldn't read header: ");
  105.         return(-1);
  106.         }
  107.     if (ArchiveDir->ArcMark != 0x1A) {
  108.         printf("invalid ArcMark: ");
  109.         return(-1);
  110.         }
  111.     if (ArchiveDir->HeaderVersion == 0) return(0);
  112.  
  113.     fseek(ArcFile, ArchiveDir->Size, SEEK_CUR);
  114.     return(1);
  115.     }
  116.